package leetcode.code0622;

public class MyCircularQueue {

	int[] queue;
	int front, rear;
	int k;
	int size;

	public MyCircularQueue(int k) {
		queue = new int[k];
		front = 0;
		rear = 0;
		this.k = k;
		size = 0;
	}

	public boolean enQueue(int value) {
		if (size == k) {
			return false;
		}
		queue[rear] = value;
		rear++;
		rear %= k;
		size++;
		return true;
	}

	public boolean deQueue() {
		if (size == 0) {
			return false;
		}
		front++;
		front %= k;
		size--;
		return true;
	}

	public int Front() {
		return size == 0 ? -1 : queue[front];
	}

	public int Rear() {
		return size == 0 ? -1 : queue[rear == 0 ? k - 1 : rear - 1];
	}

	public boolean isEmpty() {
		return size == 0;
	}

	public boolean isFull() {
		return size == k;
	}

}
